package com.study.bigdata.spark.core.summer.common

import com.study.bigdata.spark.core.summer.util.EnvCache
import org.apache.spark.{SparkConf, SparkContext}


trait TApplication {


  def execute(master : String="local[*]",appName : String)(op : =>Unit): Unit = {
    val conf = new SparkConf().setMaster(master).setAppName(appName)
    val sc = new SparkContext(conf)
    EnvCache.put(sc)
    println("开启环境")

    try {
      op
    }catch {
      case e : Exception => e.printStackTrace()
    }
    sc.stop()

    EnvCache.clear()
  }
}
